package qsoft.omanga.business.component;

import android.content.Context;

import java.util.List;

import qsoft.omanga.base.dao.MangaDAO;
import qsoft.omanga.base.sao.MangaHandler;
import qsoft.omanga.business.entities.Manga;

/**
 * 
 * @author sontt
 * 
 */
public class MangaBusiness {
    /**
     * 
     */
    private MangaDAO mangaDAO;
    /**
     * 
     */
    private Context context;

    /**
     * @param context
     *            Context
     */
    public MangaBusiness(Context context) {
        this.context = context;
        mangaDAO = new MangaDAO(context);
    }

    /**
     * @param order
     *            String
     * @return ArrayList<Manga>
     */
    public List<Manga> getAllManga(String order) {
        return mangaDAO.getAllManga(order);
    }

    /**
     * @param manga
     *            Manga
     * @return long
     */
    public long insert(Manga manga) {
        long result = -1;
        if (!existManga(manga.getId())) {
            result = mangaDAO.insert(manga);
        }
        return result;
    }

    /**
     * @param mangaId
     *            String
     * @return boolean
     */
    public boolean existManga(String mangaId) {
        return mangaDAO.existManga(mangaId);
    }

    /**
     * @param mangaId
     *            String
     * @return manga
     */
    public Manga getManga(String mangaId) {
        Manga manga = new Manga();
        // ChapterDAO chapterDAO = new ChapterDAO(context);
        manga = mangaDAO.getManga(mangaId);
        // manga.setChapters(chapterDAO.getChapters(mangaId));
        return manga;
    }

    /**
     * @return List<Manga>
     */
    public List<Manga> getListNewFromService() {
        MangaHandler mangaHandler = new MangaHandler(context);
        return mangaHandler.getListManga();
    }
}
